<template>
  <up-popup :show="show" mode="bottom" :round="10" @close="handleCancel">
		<view class='popup'>
      <div class="popup-header">
        <view class="popup-title">添加门店</view>
      </div>
      <scroll-view class="popup-content" scroll-y>
        <up-form class="p-[30rpx]" label-width="150rpx" ref="formRef">
          <up-form-item label="门店名称">
            <up-input v-model="formData.title" placeholder="请输入门店名称"></up-input>
          </up-form-item>
          <up-form-item label="登录账号">
            <up-input v-model="formData.account" placeholder="请输入登录账号"></up-input>
          </up-form-item>
          <up-form-item label="登录密码">
            <up-input v-model="formData.password" type="password" placeholder="请输入登录密码"></up-input>
          </up-form-item>
          <up-form-item label="手机号码">
            <up-input v-model="formData.mobile" placeholder="请输入手机号"></up-input>
          </up-form-item>
        </up-form>
      </scroll-view>
      <div class="popup-footer">
        <up-button type="primary" block plain @click="handleCancel">取 消</up-button>
        <up-button class="ml-[30rpx]" type="primary" block @click="handleConfirm">确 定</up-button>
      </div>
		</view>
	</up-popup>
</template>
<script lang="ts" setup>
import { addStoreApi } from '@/addon/htscrm/api';
import { debounce } from '@/utils/common';
import { ref } from 'vue'

const emit = defineEmits(['cancel', 'confirm'])

const show = ref(false)
const formData = ref<any>({
  title: '',
  account: '',
  password: '',
  confirm_password: '',
  mobile: '',
})
function close () {
	show.value = false
}
function open () {
  formData.value = {
    title: '',
    account: '',
    password: '',
    confirm_password: '',
    mobile: '',
  }
  show.value = true
}

function handleCancel() {
  close()
  emit('cancel')
}

const handleConfirm = debounce(async() =>{
  await addStoreApi(formData.value)
  close()
  emit('confirm')
  uni.showToast({title:'创建成功',icon:"none"})
})


defineExpose({
  open,
  close
})
</script>

<style scoped lang="scss">
.popup {

	.popup-header {
    height: 100rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 10rpx rgba(0, 0, 0, 0.1);

    .popup-title {
      font-size: 32rpx;
      font-weight: 500;
    }
	}

	.popup-content {
	}

  .popup-footer {
    display: flex;
    padding: 20rpx 30rpx;
    box-shadow: 0 0 10rpx rgba(0, 0, 0, 0.1);

  }
}
</style>